package com.ptu.spzx.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ptu.spzx.domain.Class.ClassesCourse;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author YT
 * @since 2024-01-28
 */


@Mapper
public interface ClassesCourseMapper extends BaseMapper<ClassesCourse> {
    @Insert("insert into classes_course (classes_id, belong_course_id) values (#{classId},#{belongCourseId})")
    public int addCourseToClass(ClassesCourse classesCourse);

    @Delete("delete from classes_course where classes_id = #{classId} and belong_course_id = #{courseId}")
    public int deleteCourseIdFromClass(Long classId,Long courseId);

    @Delete("delete from classes_course where classes_id = #{classId}")
    public int deleteClass(Long classId);

    //查询班级有什么课程
    @Select("select belong_course_id  from classes_course  where classes_id = #{classId} order by belong_course_id ")
    public List<Long> queryCoursesByClassId(Long classId);

    //查询班级里是否上这个课程,记得返回的是boolean
    @Select("select count(*)>=1 from classes_course where classes_id = #{classId} and belong_course_id = #{courseId}")
    public Boolean queryRelationExists(Long classId, Long courseId);


    @Delete("DELETE FROM classes_course WHERE classes_id=#{classId}")
    Integer deleteByClassId(Long classId);

    @Select("SELECT belong_course_id from classes_course WHERE classes_id=#{id}")
    List<Long> selectCourseIdByClassId(Long id);

    @Select("SELECT classes_id from classes_course WHERE belong_course_id=#{courseId}")
    List<Long> selectClassIdByCourseId(Long courseId);
}